<?php

/*
 * core/session.php
 *
 * Enable session handling and visitor counting.
 * Must be included before anything.
 */

/*
 * HOW TO AVOID COOKIES AND USE 'SID' INSTEAD:
 * 1) the client must know the SID so it add it to every RPC call
 * 2) a) the client call an rpc to retreive it
 *    b) we can add the SID value in an hidden <div> in www.php that the client is retreiving when onModuleLoad()
 *
 * CURRENTLY: use cookies, as soon as session.php is included first
 */

session_start();

$_isSessionStarted = false;

/*
 * isSessionStart()
 * return true if the session is currently starting (initializing)
 */
function isSessionStart()
{
	global $_isSessionStarted;
	return $_isSessionStarted;
}

// TODO: let's modules initialize their own variables
function createCoreSession()
{
	$_SESSION['core'] = array();

	$_SESSION['core']['locale'] = null;

	$_SESSION['core']['conf'] = null;

	$_SESSION['core']['user'] = array();
	$_SESSION['core']['user']['authenticated'] = false;
	$_SESSION['core']['user']['name'] = '';
	$_SESSION['core']['user']['id'] = -1;
	$_SESSION['core']['user']['group'] = array();

	$_SESSION['core']['permissions'] = array();
}

// create core session variable if not exist
if( !isset($_SESSION['core']) )
{
	global $_isSessionStarted;

	createCoreSession();

	$_isSessionStarted = true;
}

?>
